package test.lambda

data class Person(val name: String, val age: Int) {

}

//求List中age最大
fun main(args: Array<String>) {
    val people = listOf(
        Person("jack", 29),
        Person("jack", 21),
        Person("jack", 22)
    )
    //传统方法
    //findTheOldest(people)
    //lambda表达式
    //println(people.maxBy { it.age })
    println(sum(1, 3))
}

fun findTheOldest(people: List<Person>) {
    var maxAge = 0
    var theOldest: Person? = null
    for (person in people) {
        if (person.age > maxAge) {
            maxAge = person.age
            theOldest = person
        }
    }
    println(theOldest)
}


val sum = { arg1: Int, arg2: Int ->
    //println("$arg1 + $arg2 = ${arg1 + arg2}")
    arg1 + arg2
}
